//
// Created by LiuDongPeng on 2024/1/11.
//

#include "utils.h"



__STATIC_INLINE uint32_t LL_SYSTICK_IsActiveCounterFlag()
{
    return ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == (SysTick_CTRL_COUNTFLAG_Msk));
}




/**
 * @brief Get system micros
 */
uint32_t get_sys_micros()
{
    uint32_t millis = HAL_GetTick();
    __IO uint32_t tms = SysTick->LOAD + 1;
    __IO uint32_t u = tms - SysTick->VAL;

    if (LL_SYSTICK_IsActiveCounterFlag())
    {
        millis = HAL_GetTick();
        u = tms - SysTick->VAL;
    }

    return (millis * 1000 + (u * 1000) / tms);
}